#include <iostream>
using namespace std;
const int &MAX = 10000;
const int &NIL = -1;
struct Node {int parent, left, right;};
Node T[MAX];
int n;

// 前序遍历
void preParse(int u) {
    if (u == NIL) return;
    cout << " " << u;
    preParse(T[u].left);
    preParse(T[u].right);
}
// 中序遍历
void inParse(int u) {
    if (u == NIL) return;
    inParse(T[u].left);
    cout << " " << u;
    inParse(T[u].right);
}
// 后序遍历
void postParse(int u) {
    if (u == NIL) return;
    postParse(T[u].right);
    postParse(T[u].left);
    cout << " " << u;
}
int main() {
    int i, v, l, r, root;
    cin >> n;
    // 初始化树集
    for (i = 0; i < n; ++i) T[i].parent = NIL;
    // 读取树集
    for (i = 0; i < n; ++i) {
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }
    // 寻找根节点
    for (i = 0; i < n; ++i) if (T[i].parent == NIL) root = i;
    cout << "Preorder: " << endl;
    preParse(root);
    cout << endl;
    cout << "Inorder: " << endl;
    inParse(root);
    cout << endl;
    cout << "Postorder: " << endl;
    postParse(root);
    cout << endl;
    return 0;
}